﻿<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>图纸管理</title>
    <link href="../../Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="../../Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="../../Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="../../Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="../../Content/themes/icon.css" rel="stylesheet" />
    <link href="../../Content/themes/table.css" rel="stylesheet" />
    <link href="../../Content/formstyles.css" rel="stylesheet" />
    <script src="../../Content/js/common.js"></script>  
</head>
<body>   
    <div id="ui_main_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'center',border:false">
            <table id="ui_main_dg"></table> 
</div>
        <div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:[{
				text:'下发图纸',
				iconCls:'icon-ok',
				handler:function(){saveEntry()}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){$('#dlg').dialog('close')}
			}]">
            <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
                <div style="margin-bottom:2px">
                    <input name="mainItemCode" id="mainItemCode" class="easyui-combox" data-options="label:'主物料代码:', required:true,"  style="width:100%">
                </div>
                <div style="margin-bottom:10px">
                    <input name="mainItemName" id="mainItemName" class="easyui-textbox" label="主物料名称:" style="width:100%" data-options="editable:false,">
                </div>
                <div style="margin-bottom:2px">
                    <input class="easyui-textbox" name="subItemCode" id="subItemCode" data-options="label:'子物料代码:', required:true," style=" width:100%">
                </div>
                <div style="margin-bottom:10px">
                    <input name="subItemName" id="subItemName" class="easyui-textbox" label="子物料名称:" style="width:100%" data-options="editable:false,">
                </div>              
                <div style="margin-bottom:10px">
                    <input name="d_remark" id="d_remark" class="easyui-textbox" label="备注:" style="width:100%">
                </div>
            </form>
        </div>

        <script type="text/javascript">
            var columns = [[
                         { field: "drawId", width: "120", title: "子物料名称", align: 'center',hidden:true },
                         { field: "mainitemcode", width: "120", title: "主物料代码", align: 'center' },
                         { field: "mainItemName", width: "180", title: "主物料名称", align: 'center',formatter: showLongString, },
                         { field: "subItemCode", width: "120", title: "子物料代码", align: 'center' },
                         { field: "subItemName", width: "120", title: "子物料名称", align: 'center', formatter: showLongString, },
                         { field: "issueBy", width: "120", title: "图纸下发", align: 'center' },
                         { field: "issueTime", width: "150", title: "图纸下发时间", align: 'center' ,formatter: getDate},
                         { field: "confirmBy", width: "120", title: "图纸确认", align: 'center' },
                         { field: "confirmTime", width: "150", title: "图纸确认时间", align: 'center',formatter: getDate },                          
                         { field: "remark", width: "200", title: "备注", align: 'center' }, 
            ]]
    
        function ui_main_exportdata() {
            $.show_alert("消息", "功能待发布！");
        }

        var lock = false;
    //下发图纸
        function saveEntry() {
           
            if (!$("#fm").form('validate')) {//表单校验
                $.show_alert("错误", "表单校验未通过！请注意录入数据格式");
                return;
            } else {
                if (lock) { return; } else { lock = true;  }
            }
            $.ajax({
                url: "/Draw/issueDraw",
                type: "post",
                data: {
                    "mainItemCode": $('#mainItemCode').combobox("getText"),
                    "mainItemName": $('#mainItemCode').combobox("getValue"),
                    "subItemCode": $('#subItemCode').combobox("getText"),
                    "subItemName": $('#subItemCode').combobox("getValue"),
                    "drawId": uuid(20, 10),
                    "remark": $('#d_remark').textbox('getValue'),
                },
                dataType: 'json',//html\script\text\xml\json
                beforeSend: function () { },//
                complete: function () { lock = false; },
                timeout: 1000,
                success: function (data) {
                    if (data.success) {
                        $.show_alert("成功", "下发成功！");
                        $('#fm').form('clear');
                        $('#dlg').dialog('close');
                        $("#ui_main_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                    } else {
                        $.show_alert("提示", data.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                },
               
            });
        }

        $(function () {          
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "drawMgr", "KeyName": "drawMgr" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {
                        //前端添加按钮
                        //data.toolbar.push({ "text": "查看", "id": "lookbill", "iconCls": "icon-more", "handler": "lookbill();" })
                        var toolbar = getToolBar(data);      //common.js
                        if (data.search) {     //判断是否有浏览权限 
                            $("#ui_main_dg").datagrid({       //初始化datagrid
                                url: "/Draw/getDrawList?&r=" + Math.random(),
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                                queryParams: {
                                   // "view": viewdata.view,
                                },
                                idField: 'drawId',
                                sort: 'issueTime',
                                order: 'desc',
                                pageList: [20, 40, 60, 80, 100],
                                frozenColumns: [[]],
                                columns: columns,
                                toolbar: toolbar.length == 0 ? null : toolbar,
                                onSelect: function (rowIndex, rowData) {
                                  //  menuControl();
                                },
                                onLoadSuccess: function (data) {  }
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })
            //回车搜索
            $("#ui_main_search").find('input').on('keyup', function (event) {
                if (event.keyCode == '13') {
                    ui_main_searchdata();
                }
            })
        });
            //删除，取消下发图纸
        function DeldrawMgr() {
            var row = $("#ui_main_dg").datagrid("getSelected");
            if (row == null || row.length < 1) {
                $.show_alert("提示", "请先勾选要删除的图纸");
                return;
            }
            if (row.drawId == null || row.drawId == '') {
                $("#ui_main_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            if (row.confirmBy.length > 2) {
                $.show_alert("提示", "该图纸已确认，无法删除");
                return;
            }
            $.ajax({
                url: "/Draw/delDraw",
                type: "post",
                data: {
                    "drawId": row.drawId,
                },
                dataType: 'json',//html\script\text\xml\json
                // beforeSend: function () { },//
                // complete: function () { lock = false; },
                timeout: 1000,
                success: function (data) {
                    if (data.success) {
                        $.show_alert("成功", "删除成功！");
                        $("#ui_main_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                    } else {
                        $.show_alert("提示", data.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                },
            });


        }
            //确认图纸
        function confirmdrawMgr() {
            var row = $("#ui_main_dg").datagrid("getSelected");
            if (row == null || row.length < 1) {
                $.show_alert("提示", "请先勾选要确认的图纸");
                return;
            }
            if (row.drawId == null || row.drawId == '') {
                $("#ui_main_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            if (row.confirmBy.length>2) {
                $.show_alert("提示", "该图纸已确认");
                return;
            }
            $.ajax({
                url: "/Draw/confirmDraw",
                type: "post",
                data: {                    
                    "drawId": row.drawId,
                },
                dataType: 'json',//html\script\text\xml\json
               // beforeSend: function () { },//
               // complete: function () { lock = false; },
                timeout: 1000,
                success: function (data) {
                    if (data.success) {
                        $.show_alert("成功", "确认成功！");
                        //$('#fm').form('clear');
                        //$('#dlg').dialog('close');
                        $("#ui_main_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                    } else {
                        $.show_alert("提示", data.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                },
            });
        }

        //取消确认图纸
        function unconfirmdrawMgr() {
            var row = $("#ui_main_dg").datagrid("getSelected");
            if (row == null || row.length < 1) {
                $.show_alert("提示", "请先勾选要取消确认的图纸");
                return;
            }
            if (row.drawId == null || row.drawId == '') {
                $("#ui_main_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            if (row.confirmBy==null||row.confirmBy=="") {
                $.show_alert("提示", "该图纸未确认");
                return;
            }
            $.ajax({
                url: "/Draw/confirmDraw",
                type: "post",
                data: {
                    "drawId": row.drawId,
                    "type":'unConfirm'
                },
                dataType: 'json',//html\script\text\xml\json
                // beforeSend: function () { },//
                // complete: function () { lock = false; },
                timeout: 1000,
                success: function (data) {
                    if (data.success) {
                        $.show_alert("成功", "取消确认成功！");
                        $("#ui_main_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                    } else {
                        $.show_alert("提示", data.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                },

            });

        }


            //下发图纸
        function assigndrawMgr() {
            $('#dlg').dialog('open').dialog('center').dialog('setTitle', '下发图纸');           
           // url = "../../Financial/ExpenseClaimEntyHandle?claimId=" + claimId + "&method=insert" + "&rowId=" + rowId;
            $('#mainItemCode').combobox({
                mode: 'remote',  //模式： 远程获取数据
                url: '/Common/AutoComplete_ItemCode',  //远程数据请求地址
                valueField: 'FName', 　　//value对应的属性字段
                textField: 'FNumber',　　　 //text对应的属性字段
                formatter: function (row) {
                    var opts = $(this).combobox('options');
                    return row[opts.textField] + " " + row[opts.valueField];
                },
                onChange: function (newValue, oldValue) {
                    $("#mainItemName").textbox('setValue', newValue);
                    
                    $('#subItemCode').combobox({
                        url: '/Bom/getBomChildItem?q='+ $('#mainItemCode').combobox("getText"),
                        valueField: 'FName',
                        textField: 'FNumber',
                        formatter: function (row) {
                            var opts = $(this).combobox('options');
                            return row[opts.textField] + " " + row[opts.valueField];
                        },
                        onChange: function (newValue, oldValue) {
                            $("#subItemName").textbox('setValue', newValue);
                        }
                    }); 
                }

            });
            $('#fm').form('clear');
        }

    

        </Script>
</div>    
</body>
    </html>
